﻿function loadDHBC(success) {
    document.getElementById("game_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("game_area").innerHTML = xhttp.responseText;
            $("#game-question-list li").click(function () {
                $("#game-question-list li").removeClass("w3-leftbar w3-border-teal");
                $(this).addClass("w3-leftbar w3-border-teal");
                $("#game-add-question-form").css("display", "none");
                $("#game-edit-question-form").css("display", "block");
            });
            $("#add_dhbc_question").on("change", function () {
                var img = document.getElementById("add_dhbc_question").value;
                document.getElementById("add_dhbc_review").src = img;
            });
            $("#edit_dhbc_question").on("change", function () {
                var img = document.getElementById("edit_dhbc_question").value;
                document.getElementById("edit_dhbc_review").src = img;
            });
            if (success != "") {
                document.getElementById("success_content").innerHTML = success;
                document.getElementById("success-modal").style.display = "block";
                setTimeout('$("#success-modal").fadeOut()', 3000);
            }
        }
    };
    xhttp.open("GET", "../ajax/asp/Game/DHBC.aspx", true);
    xhttp.send();
}
function loadReverse(success) {
    document.getElementById("game_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("game_area").innerHTML = xhttp.responseText;
            $("#game-question-list li").click(function () {
                $("#game-question-list li").removeClass("w3-leftbar w3-border-teal");
                $(this).addClass("w3-leftbar w3-border-teal");
                $("#game-add-question-form").css("display", "none");
                $("#game-edit-question-form").css("display", "block");
            });
            $("#add_reverse_question").on("change", function () {
                var img = document.getElementById("add_reverse_question").value;
                document.getElementById("add_reverse_review").src = img;
            });
            $("#edit_reverse_question").on("change", function () {
                var img = document.getElementById("edit_reverse_question").value;
                document.getElementById("edit_reverse_review").src = img;
            });
            if (success != "") {
                document.getElementById("success_content").innerHTML = success;
                document.getElementById("success-modal").style.display = "block";
                setTimeout('$("#success-modal").fadeOut()', 3000);
            }
        }
    };
    xhttp.open("GET", "../ajax/asp/Game/Reverse.aspx", true);
    xhttp.send();
}
function loadVideo(success) {
    document.getElementById("game_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("game_area").innerHTML = xhttp.responseText;
            $("#game-question-list li").click(function () {
                $("#game-question-list li").removeClass("w3-leftbar w3-border-teal");
                $(this).addClass("w3-leftbar w3-border-teal");
                $("#game-add-question-form").css("display", "none");
                $("#game-edit-question-form").css("display", "block");
            });
            $("#add_video_question").on("change", function () {
                var img = document.getElementById("add_video_question").value;
                document.getElementById("add_video_question_review").src = img;
                document.getElementById("add_video_question_review").poster = "../Content/avatar/logosqt.png";
            });
            $("#add_video_answer").on("change", function () {
                var img = document.getElementById("add_video_answer").value;
                document.getElementById("add_video_answer_review").src = img;
                document.getElementById("add_video_answer_review").poster = "../Content/avatar/logosqt.png";
            });
            if (success != "") {
                document.getElementById("success_content").innerHTML = success;
                document.getElementById("success-modal").style.display = "block";
                setTimeout('$("#success-modal").fadeOut()', 3000);
            }
        }
    };
    xhttp.open("GET", "../ajax/asp/Game/Video.aspx", true);
    xhttp.send();
}
function loadCrossWord(success) {
    document.getElementById("game_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("game_area").innerHTML = xhttp.responseText;
            $("#game-question-list li").click(function () {
                $("#game-question-list li").removeClass("w3-leftbar w3-border-teal");
                $(this).addClass("w3-leftbar w3-border-teal");
                $("#game-add-question-form").css("display", "none");
                $("#game-edit-question-form").css("display", "block");
            });
            $(".game-create-alphabets-table-btn").click(function () {
                var r = $(this).parent().parent().find("#game-apb-table-row-number").val();
                var c = $(this).parent().parent().find("#game-apb-table-col-number").val();
                var tablebox = $("#game-apb-table-box");
                if (r > 0 && c > 0) {
                    tablebox.html("");
                    tablebox.append("<table id='game-new-apb-table' class='game-new-apb-table'></table>");
                    for (var i = -1; i < parseInt(r) + 1; i++) {
                        if (i == -1) {
                            $("#game-new-apb-table").append("<tr class='first-row row" + i + "'></tr>");
                        }
                        else if (i == parseInt(r)) {
                            $("#game-new-apb-table").append("<tr class='last-row row" + i + "'></tr>");
                        }
                        else $("#game-new-apb-table").append("<tr id='row" + i + "' class='another-row row" + i + "'></tr>");
                    }
                    for (var j = -1; j < parseInt(c) + 1; j++) {
                        if (j == -1) {
                            $("#game-new-apb-table").find("tr.first-row").append("<td></td>");
                            $("#game-new-apb-table").find("tr.another-row").append("<td><a onclick='game_add_horizol(this.parentElement.parentElement.id)' title='Thêm câu hỏi hàng ngang' class='game-apb-table-add-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-plus'></i></a><a onclick='game_edit_horizol(this.parentElement.parentElement.id)' title='Chỉnh sửa câu hỏi hàng ngang' class='game-apb-table-edit-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-cog'></i></a><div class='game-apb-table-horizol-question-box w3-hide'></div></td>");
                            $("#game-new-apb-table").find("tr.last-row").append("<td></td>");
                        }
                        else if (j == parseInt(c)) {
                            $("#game-new-apb-table").find("tr.first-row").append("<td></td>");
                            $("#game-new-apb-table").find("tr.another-row").append("<td><a onclick='game_delete_horizol(this.parentElement.parentElement.id)' title='Xoá hàng ngang này' class='game-apb-table-delete-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-times'></i></a></td>");
                            $("#game-new-apb-table").find("tr.last-row").append("<td></td>");
                        }
                        else {
                            $("#game-new-apb-table").find("tr.first-row").append("<td class='col" + j + "'><a onclick='game_choose_vertical(this.parentElement.className," + j + ")' title='Chọn từ khoá hàng dọc' class='game-apb-table-option-btn game-apb-table-choose-vertical-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-chevron-down'></i></a><a onclick='game_cancel_vertical()' title='Chọn lại từ khoá hàng dọc' class='game-apb-table-option-btn game-apb-table-cancel-vetical-btn w3-btn w3-deep-orange'><i class='fa fa-chevron-up'></i></a></td>");
                            $("#game-new-apb-table").find("tr.another-row").append("<td class='col" + j + "'><input type='text' maxlength='1' placeholder='?' disabled='disabled' /></td>");
                            $("#game-new-apb-table").find("tr.last-row").append("<td class='col" + j + "'><a onclick='game_delete_vertical(this.parentElement.className)' title='Xoá hàng dọc này' class='game-apb-table-option-btn game-apb-table-delete-vertical-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-times'></i></a></td>");
                        }
                    }
                    $("#game-new-apb-table").css("display", "inline-block");
                }
                else {
                    tablebox.html("");
                    tablebox.append("<div id='game-apb-table-tutorial' class='w3-light-grey w3-padding-64'>" +
                                        "<p class='w3-large w3-text-grey'>Nhập vào số hàng và số cột lớn hơn 0 để tạo ô chữ</p>" +
                                        "<i class='w3-xxlarge fa fa-table w3-text-grey'></i>" +
                                    "</div>");
                }
                $(".game-add-vertical-area").val("");
                $("#game-apb-table-add-vertical").css("display", "none");
            })
            if (success != "") {
                document.getElementById("success_content").innerHTML = success;
                document.getElementById("success-modal").style.display = "block";
                setTimeout('$("#success-modal").fadeOut()', 3000);
            }
        }
    };
    xhttp.open("GET", "../ajax/asp/Game/CrossWord.aspx", true);
    xhttp.send();
}
$(document).ready(function () {
    $("#game-choose").on("change", function () {
        var game_type = $(this).val();
        if (game_type > 0) {
            $("#game-setup-btn").css("display", "inline-block");
        }
        else {
            $("#game-setup-btn").css("display", "none");
        }

        if (game_type == 1) {
            loadDHBC("");
        }
        else {
            if (game_type == 2) {
                loadReverse("");
            }
            else {
                if (game_type == 3) {
                    loadVideo("");
                }
                else {
                    if (game_type == 4) {
                        loadCrossWord("");
                    }
                    else {
                        document.getElementById("game_area").innerHTML = "";
                    }
                }
            }
        }
    });
    $("#game-setup-btn").click(function () {
        $("#game-setup-modal").fadeIn();
    });
})
function game_add_question() {
    $("#game-add-question-form").css("display", "block");
    $("#game-edit-question-form").css("display", "none");
}
function game_delete_question(id) {
    $("#game-delete-question-modal").fadeIn();
    document.getElementById("delete_id").innerHTML = id;
}
function btn_add_dhbc() {
    var name = document.getElementById("add_dhbc_name").value;
    var question = document.getElementById("add_dhbc_question").value;
    var answer = document.getElementById("add_dhbc_answer").value;

    if (name.trim().length <= 2) {
        document.getElementById("error_content").innerHTML = "Tên câu hỏi quá ngắn";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
    else {
        if (answer.trim() == "") {
            document.getElementById("error_content").innerHTML = "Câu trả lời không được để trống";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        }
        else {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    loadDHBC("Thêm câu hỏi thành công");
                }
            };
            xhttp.open("POST", "../ajax/asp/Game/add_dhbc.aspx?name=" + name + "&question=" + question + "&answer=" + answer, true);
            xhttp.send();
        }
    }
}
function dhbc_edit(id) {
    document.getElementById("game-edit-question-form").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("game-edit-question-form").innerHTML = xhttp.responseText;
            $("#edit_dhbc_question").on("change", function () {
                var img = document.getElementById("edit_dhbc_question").value;
                document.getElementById("edit_dhbc_review").src = img;
            });
        }
    };
    xhttp.open("GET", "../ajax/asp/Game/edit_DHBC.aspx?id=" + id, true);
    xhttp.send();
}

function btn_edit_dhbc(id) {
    var name = document.getElementById("edit_dhbc_name").value;
    var question = document.getElementById("edit_dhbc_question").value;
    var answer = document.getElementById("edit_dhbc_answer").value;

    if (name.trim().length <= 2) {
        document.getElementById("error_content").innerHTML = "Tên câu hỏi quá ngắn";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
    else {
        if (answer.trim() == "") {
            document.getElementById("error_content").innerHTML = "Câu trả lời không được để trống";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        }
        else {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    loadDHBC("Sửa câu hỏi thành công");
                }
            };
            xhttp.open("POST", "../ajax/asp/Game/edited_dhbc.aspx?id=" + id + "&name=" + name + "&question=" + question + "&answer=" + answer, true);
            xhttp.send();
        }
    }

}
function btn_accept_delete() {
    var type = document.getElementById("game-choose").value;
    var id = document.getElementById("delete_id").innerHTML;
    if (type == 1) {
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("game-delete-question-modal").style.display = "none";
                loadDHBC("Xóa câu hỏi thành công");
            }
        };
        xhttp.open("POST", "../ajax/asp/Game/delete_dhbc.aspx?id=" + id, true);
        xhttp.send();
    }
    else {
        if (type == 2) {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    document.getElementById("game-delete-question-modal").style.display = "none";
                    loadReverse("Xóa câu hỏi thành công");
                }
            };
            xhttp.open("POST", "../ajax/asp/Game/delete_reverse.aspx?id=" + id, true);
            xhttp.send();
        }
        else {
            if (type == 3) {
                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                        document.getElementById("game-delete-question-modal").style.display = "none";
                        loadVideo("Xóa câu hỏi thành công");
                    }
                };
                xhttp.open("POST", "../ajax/asp/Game/delete_video.aspx?id=" + id, true);
                xhttp.send();
            }
            else {
                if (type == 4) {
                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            document.getElementById("game-delete-question-modal").style.display = "none";
                            loadCrossWord("Xóa câu hỏi thành công");
                        }
                    };
                    xhttp.open("POST", "../ajax/asp/Game/delete_crossword.aspx?id=" + id, true);
                    xhttp.send();
                }
            }
        }
    }
}
function btn_add_reverse() {
    var name = document.getElementById("add_reverse_name").value;
    var question = document.getElementById("add_reverse_question").value;
    var answer = document.getElementById("add_reverse_answer").value;

    if (name.trim().length <= 2) {
        document.getElementById("error_content").innerHTML = "Tên câu hỏi quá ngắn";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
    else {
        if (answer.trim() == "") {
            document.getElementById("error_content").innerHTML = "Câu trả lời không được để trống";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        }
        else {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    loadReverse("Thêm câu hỏi thành công");
                }
            };
            xhttp.open("POST", "../ajax/asp/Game/add_reverse.aspx?name=" + name + "&question=" + question + "&answer=" + answer, true);
            xhttp.send();
        }
    }
}
function reverse_edit(id) {
    document.getElementById("game-edit-question-form").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("game-edit-question-form").innerHTML = xhttp.responseText;
            $("#edit_reverse_question").on("change", function () {
                var img = document.getElementById("edit_reverse_question").value;
                document.getElementById("edit_reverse_review").src = img;
            });
        }
    };
    xhttp.open("GET", "../ajax/asp/Game/edit_reverse.aspx?id=" + id, true);
    xhttp.send();
}
function btn_edit_reverse(id) {
    var name = document.getElementById("edit_reverse_name").value;
    var question = document.getElementById("edit_reverse_question").value;
    var answer = document.getElementById("edit_reverse_answer").value;

    if (name.trim().length <= 2) {
        document.getElementById("error_content").innerHTML = "Tên câu hỏi quá ngắn";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
    else {
        if (answer.trim() == "") {
            document.getElementById("error_content").innerHTML = "Câu trả lời không được để trống";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        }
        else {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    loadReverse("Sửa câu hỏi thành công");
                }
            };
            xhttp.open("POST", "../ajax/asp/Game/edited_reverse.aspx?id=" + id + "&name=" + name + "&question=" + question + "&answer=" + answer, true);
            xhttp.send();
        }
    }

}
function btn_add_video() {
    var name = document.getElementById("add_video_name").value;
    var question = document.getElementById("add_video_question").value;
    var answer = document.getElementById("add_video_answer").value;
    var question_content = $("#add_video_question_content").val();
    if (name.trim().length <= 2) {
        document.getElementById("error_content").innerHTML = "Tên câu hỏi quá ngắn!";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
    else {
        if (question_content.trim() == "")
        {
            document.getElementById("error_content").innerHTML = "Nội dung câu hỏi không được để trống!";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        } else
        {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    loadVideo("Thêm câu hỏi thành công");
                }
            };
            xhttp.open("POST", "../ajax/asp/Game/add_video.aspx?name=" + name + "&question=" + question +"&question_content="+question_content+ "&answer=" + answer, true);
            xhttp.send();
        }
        
    }
}
function video_edit(id) {
    document.getElementById("game-edit-question-form").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("game-edit-question-form").innerHTML = xhttp.responseText;
            $("#edit_video_question").on("change", function () {
                var img = document.getElementById("edit_video_question").value;
                document.getElementById("edit_video_question_review").src = img;
            });
            $("#edit_video_answer").on("change", function () {
                var img = document.getElementById("edit_video_answer").value;
                document.getElementById("edit_video_answer_review").src = img;
            });
        }
    };
    xhttp.open("GET", "../ajax/asp/Game/edit_video.aspx?id=" + id, true);
    xhttp.send();
}
function btn_edit_video(id)
{
    var name = document.getElementById("edit_video_name").value;
    var question = document.getElementById("edit_video_question").value;
    var answer = document.getElementById("edit_video_answer").value;
    var question_content = $("#edit_video_question_content").val();
    if (name.trim().length <= 2) {
        document.getElementById("error_content").innerHTML = "Tên câu hỏi quá ngắn!";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
    else {
        if (question_content.trim() == "") {
            document.getElementById("error_content").innerHTML = "Nội dung câu hỏi không được để trống!";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        } else {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    loadVideo("Sửa câu hỏi thành công");
                }
            };
            xhttp.open("POST", "../ajax/asp/Game/edited_video.aspx?id="+id+"&name=" + name + "&question=" + question + "&question_content=" + question_content + "&answer=" + answer, true);
            xhttp.send();
        }

    }
}
function game_choose_vertical(that, hor) {
    var primary_hor = hor + 1;
    document.getElementById("game_add_primary_hor").innerHTML = primary_hor;
    $("#game-apb-table-add-vertical").animate({ "height": "toggle" }, "fast");
    $(".game-add-vertical-area").focus();
    $("#game-new-apb-table").find("tr.first-row td a").css("display", "none");
    $("#game-new-apb-table").find("tr.first-row td." + that + " .game-apb-table-cancel-vetical-btn").css("display", "inline-block");
    $("#game-new-apb-table").find("tr.another-row td." + that + " input").removeAttr("disabled").removeClass("w3-teal").addClass("w3-deep-orange choosen");
}
function edit_game_choose_vertical(that, hor) {
    var primary_hor = hor + 1;
    document.getElementById("game_edit_primary_hor").innerHTML = primary_hor;
    $("#edit-game-apb-table-add-vertical").animate({ "height": "toggle" }, "fast");
    $(".game-edit-vertical-area").focus();
    $("#edit-game-new-apb-table").find("tr.first-row td a").css("display", "none");
    $("#edit-game-new-apb-table").find("tr.first-row td." + that + " .game-apb-table-cancel-vetical-btn").css("display", "inline-block");
    $("#edit-game-new-apb-table").find("tr.another-row td." + that + " input").removeAttr("disabled").removeClass("w3-teal").addClass("w3-deep-orange choosen");
}
function game_done_vertical() {
    if ($(".game-add-vertical-area").val() == "") {
        document.getElementById("error_content").innerHTML = "Bạn chưa nhập câu hỏi hàng dọc!";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
        return false;
    }
    else {
        var keywords = $("#game-new-apb-table").find("tr td input.choosen");
        var dem = 0;
        for (var i = 0; i < keywords.length; i++) {
            if ($(keywords[i]).val() == "") {
                dem++;
            }
        }
        if (dem > 0) {
            document.getElementById("error_content").innerHTML = "Bạn chưa nhập đủ từ khoá hàng dọc!";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
            return false;
        }
        else {
            $("#game-new-apb-table").find("tr td input.choosen").attr("disabled", "disabled");
            $("#game-apb-table-add-vertical").css("display", "none");
        }
    }
}
function edit_game_done_vertical() {
    if ($(".game-edit-vertical-area").val() == "") {
        document.getElementById("error_content").innerHTML = "Bạn chưa nhập câu hỏi hàng dọc!";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
        return false;
    }
    else {
        var keywords = $("#edit-game-new-apb-table").find("tr td input.choosen");
        var dem = 0;
        for (var i = 0; i < keywords.length; i++) {
            if ($(keywords[i]).val() == "") {
                dem++;
            }
        }
        if (dem > 0) {
            document.getElementById("error_content").innerHTML = "Bạn chưa nhập đủ từ khoá hàng dọc!";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
            return false;
        }
        else {
            $("#edit-game-new-apb-table").find("tr td input.choosen").attr("disabled", "disabled");
            $("#edit-game-apb-table-add-vertical").css("display", "none");
        }
    }
}
function game_cancel_vertical() {
    $("#game-apb-table-add-vertical").css("display", "none");
    $("#game-new-apb-table").find("tr.first-row td a").css("display", "none");
    $("#game-new-apb-table").find("tr.first-row td a.game-apb-table-choose-vertical-btn").css("display", "inline-block");
    $("#game-new-apb-table").find("tr.another-row td input.choosen").attr("disabled", "disabled").removeClass("w3-deep-orange choosen");
    var fullty = $("#game-new-apb-table").find("tr.done td input").not(".choosen");
    for (var i = 0; i < fullty.length; i++) {
        if ($(fullty[i]).val() != "") {
            $(fullty[i]).addClass("w3-teal");
        }
        else {
            $(fullty[i]).removeClass("w3-teal");
        }
    }
}
function edit_game_cancel_vertical() {
    $("#edit-game-apb-table-add-vertical").css("display", "none");
    $("#edit-game-new-apb-table").find("tr.first-row td a").css("display", "none");
    $("#edit-game-new-apb-table").find("tr.first-row td a.game-apb-table-choose-vertical-btn").css("display", "inline-block");
    $("#edit-game-new-apb-table").find("tr.another-row td input.choosen").attr("disabled", "disabled").removeClass("w3-deep-orange choosen");
    var fullty = $("#edit-game-new-apb-table").find("tr.done td input").not(".choosen");
    for (var i = 0; i < fullty.length; i++) {
        if ($(fullty[i]).val() != "") {
            $(fullty[i]).addClass("w3-teal");
        }
        else {
            $(fullty[i]).removeClass("w3-teal");
        }
    }
}
function game_delete_vertical(that) {
    var ask = confirm("Bạn có chắc chắn muốn xoá hàng dọc này ?");
    if (ask == true) {
        $("#game-new-apb-table").find("tr td." + that).detach();
        game_cancel_vertical();
        if ($("#game-new-apb-table tr td .game-apb-table-choose-vertical-btn").length == 0) {
            $("#game-apb-table-box").html("");
            $("#game-apb-table-box").append("<div id='game-apb-table-tutorial' class='w3-light-grey w3-padding-64'>" +
                                "<p class='w3-large w3-text-grey'>Nhập vào số hàng và số cột lớn hơn 0 để tạo ô chữ</p>" +
                                "<i class='w3-xxlarge fa fa-table w3-text-grey'></i>" +
                            "</div>");
        }
    }
    else {

    }
}
function edit_game_delete_vertical(that) {
    var ask = confirm("Bạn có chắc chắn muốn xoá hàng dọc này ?");
    if (ask == true) {
        document.getElementById("game_edit_primary_hor").innerHTML = "";
        $("#edit-game-new-apb-table ." + that).remove();
        edit_game_cancel_vertical();
        if ($("#edit-game-new-apb-table tr td .game-apb-table-choose-vertical-btn").length == 0) {
            $("#edit-game-apb-table-box").html("");
            $("#edit-game-apb-table-box").append("<div id='game-apb-table-tutorial' class='w3-light-grey w3-padding-64'>" +
                                "<p class='w3-large w3-text-grey'>Nhập vào số hàng và số cột lớn hơn 0 để tạo ô chữ</p>" +
                                "<i class='w3-xxlarge fa fa-table w3-text-grey'></i>" +
                            "</div>");
        }
    }
    else {

    }
}
function game_add_horizol(row) {
    if ($("#game-new-apb-table").find("tr").hasClass("active")) {
        game_cancel_add_horizol();
    }
    $("#game-new-apb-table").find("tr." + row).addClass("active");
    $("#game-new-apb-table").find("tr." + row + " td input").not(".choosen").removeAttr("disabled").addClass("w3-border w3-border-teal");
    $("#game-new-apb-table").find("tr." + row + " td .game-apb-table-add-horizol-btn").css("display", "none");
    $(".game-add-horizol-area").val("");
    $("#game-apb-table-add-horizol").css("display", "block");
    $(".game-apb-table-cancel-horizol-btn").css("display", "inline-block");
}
function game_edit_horizol(row) {
    if ($("#edit-game-new-apb-table").find("tr").hasClass("active")) {
        game_cancel_edit_horizol();
    }
    $("#edit-game-new-apb-table").find("tr." + row).addClass("active");
    $("#edit-game-new-apb-table").find("tr." + row + " td input").not(".choosen").removeAttr("disabled").addClass("w3-border w3-border-teal");
    $("#edit-game-new-apb-table").find("tr." + row + " td .edit-game-apb-table-add-horizol-btn").css("display", "none");
    $(".edit-game-add-horizol-area").val("");
    $("#edit-game-apb-table-add-horizol").css("display", "block");
    $(".edit-game-apb-table-cancel-horizol-btn").css("display", "inline-block");
}
function game_done_add_horizol() {
    if ($(".game-add-horizol-area").val() != "") {
        $("#game-new-apb-table").find("tr.active").find(".game-apb-table-horizol-question-box").html($(".game-add-horizol-area").val());
        $("#game-apb-table-add-horizol").css("display", "none");
        $("#game-new-apb-table").find("tr.active").find(".game-apb-table-edit-horizol-btn").css("display", "inline-block");
        $("#game-new-apb-table").find("tr.active td input").attr("disabled", "disabled").removeClass("w3-border w3-border-teal");
        $("#game-new-apb-table").find("tr.active").removeClass("active").addClass("done");
    }
    else {
        document.getElementById("error_content").innerHTML = "Bạn chưa nhập câu hỏi hàng ngang!";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
        return false;
    }
    var fullty = $("#game-new-apb-table").find("tr.done td input").not(".choosen");
    for (var i = 0; i < fullty.length; i++) {
        if ($(fullty[i]).val() != "") {
            $(fullty[i]).addClass("w3-teal");
        }
        else {
            $(fullty[i]).removeClass("w3-teal");
        }
    }
}
function game_done_edit_horizol() {
    if ($(".game-edit-horizol-area").val() != "") {
        $("#edit-game-new-apb-table").find("tr.active").find(".edit-game-apb-table-horizol-question-box").html($(".game-edit-horizol-area").val());
        $("#game-apb-table-edit-horizol").css("display", "none");
        $("#edit-game-new-apb-table").find("tr.active").find(".game-apb-table-edit-horizol-btn").css("display", "inline-block");
        $("#edit-game-new-apb-table").find("tr.active td input").attr("disabled", "disabled").removeClass("w3-border w3-border-teal");
        $("#edit-game-new-apb-table").find("tr.active").removeClass("active").addClass("done");
    }
    else {
        document.getElementById("error_content").innerHTML = "Bạn chưa nhập câu hỏi hàng ngang!";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
        return false;
    }
    var fullty = $("#edit-game-new-apb-table").find("tr.done td input").not(".choosen");
    for (var i = 0; i < fullty.length; i++) {
        if ($(fullty[i]).val() != "") {
            $(fullty[i]).addClass("w3-teal");
        }
        else {
            $(fullty[i]).removeClass("w3-teal");
        }
    }
}
function game_cancel_add_horizol() {
    $("#game-apb-table-add-horizol").css("display", "none");
    if ($("#game-new-apb-table").find("tr.active").hasClass("done")) {
        $("#game-new-apb-table").find("tr.active").find(".game-apb-table-edit-horizol-btn").css("display", "inline-block");
    }
    else {
        $("#game-new-apb-table").find("tr.active").find(".game-apb-table-add-horizol-btn").css("display", "inline-block");
    }
    $("#game-new-apb-table").find("tr.active td input").attr("disabled", "disabled").removeClass("w3-border w3-border-teal");
    $("#game-new-apb-table").find("tr.active").removeClass("active");
}
function edit_game_cancel_add_horizol() {
    $("#edit-game-apb-table-add-horizol").css("display", "none");
    if ($("#edit-game-new-apb-table").find("tr.active").hasClass("done")) {
        $("#edit-game-new-apb-table").find("tr.active").find(".game-apb-table-edit-horizol-btn").css("display", "inline-block");
    }
    else {
        $("#edit-game-new-apb-table").find("tr.active").find(".game-apb-table-add-horizol-btn").css("display", "inline-block");
    }
    $("#edit-game-new-apb-table").find("tr.active td input").attr("disabled", "disabled").removeClass("w3-border w3-border-teal");
    $("#edit-game-new-apb-table").find("tr.active").removeClass("active");
}
function game_cancel_edit_horizol() {
    $("#edit-game-apb-table-add-horizol").css("display", "none");
    if ($("#edit-game-new-apb-table").find("tr.active").hasClass("done")) {
        $("#edit-game-new-apb-table").find("tr.active").find(".game-apb-table-edit-horizol-btn").css("display", "inline-block");
    }
    else {
        $("#edit-game-new-apb-table").find("tr.active").find(".game-apb-table-add-horizol-btn").css("display", "inline-block");
    }
    $("#game-new-apb-table").find("tr.active td input").attr("disabled", "disabled").removeClass("w3-border w3-border-teal");
    $("#game-new-apb-table").find("tr.active").removeClass("active");
}
function edit_game_cancel_add_horizol() {
    $("#edit-game-apb-table-add-horizol").css("display", "none");
    if ($("#edit-game-new-apb-table").find("tr.active").hasClass("done")) {
        $("#edit-game-new-apb-table").find("tr.active").find(".game-apb-table-edit-horizol-btn").css("display", "inline-block");
    }
    else {
        $("#edit-game-new-apb-table").find("tr.active").find(".game-apb-table-add-horizol-btn").css("display", "inline-block");
    }
    $("#edit-game-new-apb-table").find("tr.active td input").attr("disabled", "disabled").removeClass("w3-border w3-border-teal");
    $("#edit-game-new-apb-table").find("tr.active").removeClass("active");
}
function game_edit_horizol(row) {
    if ($("#game-new-apb-table").find("tr").hasClass("active")) {
        game_cancel_add_horizol();
    }
    $("#game-new-apb-table").find("tr." + row).addClass("active");
    $("#game-new-apb-table").find("tr." + row + " td input").not(".choosen").removeAttr("disabled").addClass("w3-border w3-border-teal");
    $("#game-new-apb-table").find("tr." + row + " td .game-apb-table-edit-horizol-btn").css("display", "none");
    $(".game-add-horizol-area").val($("#game-new-apb-table").find("tr." + row + " td .game-apb-table-horizol-question-box").html());
    $("#game-apb-table-add-horizol").css("display", "block");
    $(".game-apb-table-cancel-horizol-btn").css("display", "none");
}
function edit_game_edit_horizol(row) {
    
    if ($("#edit-game-new-apb-table").find("tr").hasClass("active")) {
        edit_game_cancel_add_horizol();
    }
    $("#" + row).addClass("active");
    $("#"+row).find("td input").not(".choosen").removeAttr("disabled").addClass("w3-border w3-border-teal");
    $("#edit-game-new-apb-table").find(".game-apb-table-edit-horizol-btn").css("display", "inline-block");
    $("#" + row).find(".game-apb-table-edit-horizol-btn").css("display", "none");

    $(".game-edit-horizol-area").val($("#"+row).find(".edit-game-apb-table-horizol-question-box").html());
    $("#game-apb-table-edit-horizol").css("display", "block");
    $(".game-apb-table-cancel-horizol-btn").css("display", "none");
}
function game_delete_horizol(row) {
    var ask = confirm("Bạn có chắc chắn muốn xoá hàng ngang này ?");
    if (ask == true) {
        $("#game-new-apb-table").find("tr." + row).detach();
        game_cancel_add_horizol();
        if ($("#game-new-apb-table tr.another-row").length == 0) {
            $("#game-apb-table-box").html("");
            $("#game-apb-table-box").append("<div id='game-apb-table-tutorial' class='w3-light-grey w3-padding-64'>" +
                                "<p class='w3-large w3-text-grey'>Nhập vào số hàng và số cột lớn hơn 0 để tạo ô chữ</p>" +
                                "<i class='w3-xxlarge fa fa-table w3-text-grey'></i>" +
                            "</div>");
        }
    }
    else {

    }
}
function edit_game_delete_horizol(row) {
    var ask = confirm("Bạn có chắc chắn muốn xoá hàng ngang này ?");
    if (ask == true) {
        $("#"+row).remove();
        edit_game_cancel_add_horizol();
        if ($("#edit-game-new-apb-table tr.another-row").length == 0) {
            $("#edit-game-apb-table-box").html("");
            $("#edit-game-apb-table-box").append("<div id='game-apb-table-tutorial' class='w3-light-grey w3-padding-64'>" +
                                "<p class='w3-large w3-text-grey'>Nhập vào số hàng và số cột lớn hơn 0 để tạo ô chữ</p>" +
                                "<i class='w3-xxlarge fa fa-table w3-text-grey'></i>" +
                            "</div>");
        }
    }
    else {

    }
}

function btn_add_crossword() {
    var request = "";
    var primary_hor = document.getElementById("game_add_primary_hor").innerHTML;
    var name = document.getElementById("add_crossword_name").value;
    if (name.trim().length <= 2) {
        document.getElementById("error_content").innerHTML = "Tên ô chữ không được để trống";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
    else {
        request += name + ",";
        if ($("#game-new-apb-table").length != 0) {
            var ver = $("#game-new-apb-table tr").length;
            ver = ver - 2;
            if (ver > 0) {
                request += ver + ",";
                var hor = document.getElementById("game-new-apb-table").getElementsByTagName("tr")[0].getElementsByTagName("td").length;
                hor = hor - 2;
                if (hor > 0) {
                    request += hor + ",";
                    if (primary_hor.trim() == "") {
                        document.getElementById("error_content").innerHTML = "Chưa chọn cột câu trả lời chính";
                        document.getElementById("error-modal").style.display = "block";
                        setTimeout('$("#error-modal").fadeOut()', 3000);
                    }
                    else {
                        if (parseInt(primary_hor) < 0 || parseInt(primary_hor) > hor) {
                            document.getElementById("error_content").innerHTML = "Cột trả lời chính không hợp lệ!";
                            document.getElementById("error-modal").style.display = "block";
                            setTimeout('$("#error-modal").fadeOut()', 3000);
                        }
                        else {
                            if ($("#add_primary_question_crossword").val().trim() == "") {
                                document.getElementById("error_content").innerHTML = "Chưa có câu hỏi chính cho ô chữ này!";
                                document.getElementById("error-modal").style.display = "block";
                                setTimeout('$("#error-modal").fadeOut()', 3000);
                            }else
                            {
                                request += $("#add_primary_question_crossword").val() + ",";
                                request += primary_hor + ",";
                                for (var i = 1; i <= ver; i++) {
                                    request += i + "_" + document.getElementsByClassName("game-apb-table-horizol-question-box")[i - 1].innerHTML + ",";
                                }
                                for (var i = 1; i <= ver; i++) {
                                    for (var j = 1; j <= hor; j++) {
                                        request += i + "_" + j + "_" + document.getElementById("game-new-apb-table").getElementsByTagName("tr")[i].getElementsByTagName("td")[j].getElementsByTagName("input")[0].value + ",";
                                    }
                                }
                                //$.post("../Ajax/asp/game/add_crossword.aspx", { "request": request });
                                //loadCrossWord("Thêm ô chữ thành công");
                                var xhttp;
                                xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                                        loadCrossWord("Thêm ô chữ thành công");
                                    }
                                    else
                                    {
                                        document.getElementById("error_content").innerHTML = "Đã có lỗi xảy ra! <p>Xin vui lòng liên hệ IT để biết thêm chi tiết</p>";
                                        document.getElementById("error-modal").style.display = "block";
                                        setTimeout('$("#error-modal").fadeOut()', 3000);
                                    }
                                };
                                xhttp.open("POST", "../ajax/asp/Game/add_crossword.aspx", true);
                                xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                                xhttp.send("request="+request);
                            }
                        }
                    }
                }

            }
        }
        else {
            document.getElementById("error_content").innerHTML = "Không tồn tại bảng!";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        }
    }
}
function crossword_edit(id) {
    document.getElementById("game-edit-question-form").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("game-edit-question-form").innerHTML = xhttp.responseText;
            $(".game-create-alphabets-table-btn").click(function () {
                var r = $(this).parent().parent().find("#edit-game-apb-table-row-number").val();
                var c = $(this).parent().parent().find("#edit-game-apb-table-col-number").val();
                var tablebox = $("#edit-game-apb-table-box");
                if (r > 0 && c > 0) {
                    tablebox.html("");
                    tablebox.append("<table id='edit-game-new-apb-table' class='game-new-apb-table'></table>");
                    for (var i = -1; i < parseInt(r) + 1; i++) {
                        if (i == -1) {
                            $("#edit-game-new-apb-table").append("<tr class='first-row row" + i + "'></tr>");
                        }
                        else if (i == parseInt(r)) {
                            $("#edit-game-new-apb-table").append("<tr class='last-row row" + i + "'></tr>");
                        }
                        else $("#edit-game-new-apb-table").append("<tr id='row" + i + "' class='another-row row" + i + "'></tr>");
                    }
                    for (var j = -1; j < parseInt(c) + 1; j++) {
                        if (j == -1) {
                            $("#edit-game-new-apb-table").find("tr.first-row").append("<td></td>");
                            $("#edit-game-new-apb-table").find("tr.another-row").append("<td><a onclick='game_add_horizol(this.parentElement.parentElement.id)' title='Thêm câu hỏi hàng ngang' class='game-apb-table-add-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-plus'></i></a><a onclick='game_edit_horizol(this.parentElement.parentElement.id)' title='Chỉnh sửa câu hỏi hàng ngang' class='game-apb-table-edit-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-cog'></i></a><div class='game-apb-table-horizol-question-box w3-hide'></div></td>");
                            $("#edit-game-new-apb-table").find("tr.last-row").append("<td></td>");
                        }
                        else if (j == parseInt(c)) {
                            $("#edit-game-new-apb-table").find("tr.first-row").append("<td></td>");
                            $("#edit-game-new-apb-table").find("tr.another-row").append("<td><a onclick='game_delete_horizol(this.parentElement.parentElement.id)' title='Xoá hàng ngang này' class='game-apb-table-delete-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-times'></i></a></td>");
                            $("#edit-game-new-apb-table").find("tr.last-row").append("<td></td>");
                        }
                        else {
                            $("#edit-game-new-apb-table").find("tr.first-row").append("<td class='col" + j + "'><a onclick='game_choose_vertical(this.parentElement.className)' title='Chọn từ khoá hàng dọc' class='game-apb-table-option-btn game-apb-table-choose-vertical-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-chevron-down'></i></a><a onclick='game_cancel_vertical()' title='Chọn lại từ khoá hàng dọc' class='game-apb-table-option-btn game-apb-table-cancel-vetical-btn w3-btn w3-deep-orange'><i class='fa fa-chevron-up'></i></a></td>");
                            $("#edit-game-new-apb-table").find("tr.another-row").append("<td class='col" + j + "'><input type='text' maxlength='1' placeholder='?' disabled='disabled' /></td>");
                            $("#edit-game-new-apb-table").find("tr.last-row").append("<td class='col" + j + "'><a onclick='game_delete_vertical(this.parentElement.className)' title='Xoá hàng dọc này' class='game-apb-table-option-btn game-apb-table-delete-vertical-btn w3-btn w3-light-grey w3-text-teal'><i class='fa fa-times'></i></a></td>");
                        }
                    }
                    $("#edit-game-new-apb-table").css("display", "inline-block");
                }
                else {
                    tablebox.html("");
                    tablebox.append("<div id='edit-game-apb-table-tutorial' class='w3-light-grey w3-padding-64'>" +
                                        "<p class='w3-large w3-text-grey'>Nhập vào số hàng và số cột lớn hơn 0 để tạo ô chữ</p>" +
                                        "<i class='w3-xxlarge fa fa-table w3-text-grey'></i>" +
                                    "</div>");
                }
                $(".edit-game-add-vertical-area").val("");
                $("#edit-game-apb-table-add-vertical").css("display", "none");
            })
        }
    };
    xhttp.open("GET", "../ajax/asp/Game/edit_crossword.aspx?id=" + id, true);
    xhttp.send();
}
function btn_edit_crossword(id)
{
    var request = id+",";
    var primary_hor = document.getElementById("game_edit_primary_hor").innerHTML;
    var name = document.getElementById("edit_crossword_name").value;
    if (name.trim().length <= 2) {
        document.getElementById("error_content").innerHTML = "Tên câu hỏi không được để trống";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
    else {
        request += name + ",";
        if ($("#edit-game-new-apb-table").length != 0) {
            var ver = $("#edit-game-new-apb-table tr").length;
            ver = ver - 2;
            if (ver > 0) {
                request += ver + ",";
                var hor = document.getElementById("edit-game-new-apb-table").getElementsByTagName("tr")[0].getElementsByTagName("td").length;
                hor = hor - 2;
                if (hor > 0) {
                    request += hor + ",";
                    if (primary_hor.trim() == "") {
                        document.getElementById("error_content").innerHTML = "Chưa chọn cột câu trả lời chính";
                        document.getElementById("error-modal").style.display = "block";
                        setTimeout('$("#error-modal").fadeOut()', 3000);
                    }
                    else {
                        if (parseInt(primary_hor) < 0 || parseInt(primary_hor) > hor) {
                            document.getElementById("error_content").innerHTML = "Cột trả lời chính không hợp lệ!";
                            document.getElementById("error-modal").style.display = "block";
                            setTimeout('$("#error-modal").fadeOut()', 3000);
                        }
                        else {
                            if ($("#edit_primary_question_crossword").val().trim() == "") {
                                document.getElementById("error_content").innerHTML = "Chưa có câu hỏi chính cho ô chữ này!";
                                document.getElementById("error-modal").style.display = "block";
                                setTimeout('$("#error-modal").fadeOut()', 3000);
                            } else {
                                request += $("#edit_primary_question_crossword").val() + ",";
                                request += primary_hor + ",";
                                for (var i = 1; i <= ver; i++) {
                                    request += i + "_" + document.getElementsByClassName("edit-game-apb-table-horizol-question-box")[i - 1].innerHTML + ",";
                                }
                                for (var i = 1; i <= ver; i++) {
                                    for (var j = 1; j <= hor; j++) {
                                        request += i + "_" + j + "_" + document.getElementById("edit-game-new-apb-table").getElementsByTagName("tr")[i].getElementsByTagName("td")[j].getElementsByTagName("input")[0].value + ",";
                                    }
                                }
                                //$.post("../Ajax/asp/game/edited_crossword.aspx", { "request": request });
                                //loadCrossWord("Sửa ô chữ thành công");

                                var xhttp;
                                xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                                        loadCrossWord("Sửa ô chữ thành công");
                                    }
                                    
                                };
                                xhttp.open("POST", "../ajax/asp/Game/edited_crossword.aspx", true);
                                xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                                xhttp.send("request=" + request);
                            }
                        }
                    }
                }

            }
        }
        else {
            document.getElementById("error_content").innerHTML = "Không tồn tại bảng!";
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        }
    }
}